﻿using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindStyle.SPEntity;
using WindStyle.SPEntity.Attributes;
using WindStyle.SPEntity.Converters;

namespace UnitTest
{
    public class NumberEntity : Entity
    {
        [Field("Int")]
        public int Int { get; set; }

        [Field("Double")]
        public double Double { get; set; }

        [Field("Money")]
        public decimal Money { get; set; }
    }

    public class DateTimeEntity : Entity
    {
        [Field("Date")]
        public DateTime Date { get; set; }

        [Field("DateTime")]
        public DateTime DateTime { get; set; }
    }

    public class StringEntity : Entity
    {
        [Field("SingleLine")]
        public string SingleLine { get; set; }

        [Field("MultipleLine")]
        public string MultipleLine { get; set; }
    }

    public class BoolEntity : Entity
    {
        [Field("Bool")]
        public bool Bool { get; set; }
    }

    public class LinkEntity : Entity
    {
        [UrlField("Link", "Url", "Description")]
        public Link Link { get; set; }

        [UrlField("Image", UrlValue.Url)]
        public Uri ImageUrl { get; set; }

        [UrlField("Image", UrlValue.Description)]
        public string ImageDescription { get; set; }

        [UrlField("Link", UrlValue.Url)]
        public int Url { get; set; }
    }

    public class Link
    {
        public string Url { get; set; }
        public string Description { get; set; }
    }

    public class ChoiceEntity : Entity
    {
        [Field("Choice")]
        public Choice Choice { get; set; }

        [Field("MultipleChoice")]
        public Choice Choices { get; set; }
    }

    [Flags]
    public enum Choice
    {
        None = 0,
        [EnumMember("Option #1")]
        Option1 = 1,
        [EnumMember("Option #2")]
        Option2 = 2,
        [EnumMember("Option #3")]
        Option3 = 4
    }

    public class LookupEntity : Entity
    {
        [LookupField("Lookup", "SPListItemId", "Title")]
        public LookupEntity SubEntity { get; set; }

        [LookupField("Lookup", LookupValue.Id)]
        public int SubEntityId { get; set; }

        [LookupField("Lookup", LookupValue.Value)]
        public string SubEntityTitle { get; set; }

        [LookupField("MultipleLookup", "SPListItemId", "SingleLine")]
        public StringEntity[] SubEntities { get; set; }

        [LookupField("MultipleLookup", LookupValue.Id)]
        public int[] SubEntityIds { get; set; }

        [LookupField("MultipleLookup", LookupValue.Value)]
        public string[] SubEntityTitles { get; set; }
    }

    public class UserEntity : Entity
    {
        [Field("User")]
        public SPUser SPUser { get; set; }

        [LookupField("User", "Id", "DisplayName")]
        public User User { get; set; }

        [LookupField("User", LookupValue.Id)]
        public int UserId { get; set; }

        [LookupField("User", LookupValue.Value)]
        public string UserName { get; set; }

        [LookupField("Users", "Id", "DisplayName")]
        public List<User> UserCollection { get; set; }

        [LookupField("Users", LookupValue.Id)]
        public int[] UserIds { get; set; }

        [LookupField("Users", LookupValue.Value)]
        public string[] UserNames { get; set; }
    }

    public class User
    {
        public int Id { get; set; }
        public string DisplayName { get; set; }
    }

    public class ReadonlyFieldEntity : Entity
    {
        [Field("SingleLine", MappingMode.ReadOnly)]
        public string SingleLine { get; set; }
    }

    public class CustomConversionEntity : Entity
    {
        public string Price { get; set; }

        public override void Read(Microsoft.SharePoint.SPListItem item, Microsoft.SharePoint.SPRegionalSettings regionalSettings = null)
        {
            base.Read(item, regionalSettings);
            this.Price = "$" + item["Money"].ToString();
        }

        public override void Write(Microsoft.SharePoint.SPListItem item, Microsoft.SharePoint.SPRegionalSettings regionalSettings = null)
        {
            base.Write(item, regionalSettings);
            item["Money"] = double.Parse(this.Price.Substring(1));
        }
    }

    public class NotSupportFieldEntity : Entity
    {
        [Field("NotSupportField")]
        public string Value { get; set; }
    }

    [Serializable]
    public class NotSupportFieldValue
    {
        public NotSupportFieldValue() { }
        public NotSupportFieldValue(string value) { }
        public override string ToString()
        {
            return "NotSupport";
        }
    }

    public class String2GuidEntity : Entity
    {
        [Field("SingleLine")]
        public Guid Value { get; set; }
    }

    public class NullableEntity : Entity
    {
        [Field("Int")]
        public int? Int { get; set; }

        [Field("Double")]
        public double? Double { get; set; }

        [Field("Money")]
        public decimal? Decimal { get; set; }

        [Field("Date")]
        public DateTime? Date { get; set; }

        [Field("Bool")]
        public bool? Bool { get; set; }

        [Field("Choice")]
        public Choice? Choice { get; set; }

        [Field("MultipleChoice")]
        public Choice? Choices { get; set; }

        [Field("SingleLine")]
        public Guid? Guid { get; set; }
    }
}
